<template>
  <div class="page-container">
    <div v-if="hotListData.length === 0" class="loading">加载中...</div>

    <div class="hot-list-card" v-for="item in hotListData" :key="item.id">
      <div class="card-header" @click="handleListClick(item)">
        <div class="header-left">
          <div class="rank-icon">🔥</div>
          <div class="list-title">{{ item.title }}</div>
        </div>
        <div class="list-all">查看全部 <span class="arrow">→</span></div>
      </div>

      <div class="card-content" @click="handleListClick(item)">
        <div class="rank-image-wrapper">
          <div class="list-img" :style="{ backgroundImage: `url(${item.img_url})` }">
            <div class="image-overlay"></div>
          </div>
          <div class="rank-badge">
            <span>TOP 3</span>
          </div>
        </div>

        <div class="rank-list" @click.stop>
          <div class="rank-item rank-first">
            <div class="rank-number">
              <span class="number">1</span>
              <div class="crown">👑</div>
            </div>
            <div class="rank-title">{{ item.contents[0].title }}</div>
            <div class="rank-indicator first-indicator"></div>
          </div>
          <div class="rank-item rank-second">
            <div class="rank-number">
              <span class="number">2</span>
            </div>
            <div class="rank-title">{{ item.contents[1].title }}</div>
            <div class="rank-indicator second-indicator"></div>
          </div>
          <div class="rank-item rank-third">
            <div class="rank-number">
              <span class="number">3</span>
            </div>
            <div class="rank-title">{{ item.contents[2].title }}</div>
            <div class="rank-indicator third-indicator"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 排行榜详情组件 -->
    <HotRankDetail v-if="rankDetailVisible" :rankId="currentRankId" :title="currentRankTitle"
      :isVisible="rankDetailVisible" @close="closeRankDetail" />
  </div>
</template>

<script>
import { getHotRank } from '@/api/api'
import HotRankDetail from '@/components/HotRankDetail.vue'

export default {
  components: {
    HotRankDetail
  },
  data() {
    return {
      hotListData: [],
      rankDetailVisible: false,
      currentRankId: '',
      currentRankTitle: ''
    }
  },
  methods: {
    handleListClick(item) {
      this.currentRankId = item.id;
      this.currentRankTitle = item.title;
      this.rankDetailVisible = true;
    },
    closeRankDetail() {
      this.rankDetailVisible = false;
      this.currentRankId = '';
      this.currentRankTitle = '';
    }
  },
  created() {
    getHotRank()
      .then(res => {
        // console.log(res.data);
        this.hotListData = res.data;
      })
  }
}
</script>

<style scoped lang="less">
.page-container {
  padding: 10vh 15px 7vh;
  box-sizing: border-box;
  background: linear-gradient(180deg, #fef3f2 0%, #ffffff 30%);
  min-height: 100vh;
}

.hot-list-card {
  margin-bottom: 25px;
  background: #ffffff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  cursor: pointer;

  &:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  }

  .card-header {
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
    border-bottom: 1px solid #fee2e2;

    .header-left {
      display: flex;
      align-items: center;
      gap: 10px;

      .rank-icon {
        font-size: 18px;
        animation: pulse 2s ease-in-out infinite;
      }

      .list-title {
        font-size: 15px;
        font-weight: 600;
        color: #1f2937;
        letter-spacing: 0.3px;
      }
    }

    .list-all {
      font-size: 12px;
      color: #ef4444;
      font-weight: 500;
      display: flex;
      align-items: center;
      gap: 4px;

      .arrow {
        transition: transform 0.2s ease;
      }

      &:hover .arrow {
        transform: translateX(3px);
      }
    }
  }

  .card-content {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;

    .rank-image-wrapper {
      position: relative;
      width: 100%;
      height: 160px;
      border-radius: 12px;
      overflow: hidden;

      .list-img {
        width: 100%;
        height: 100%;
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
        position: relative;

        .image-overlay {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.3) 100%);
        }
      }

      .rank-badge {
        position: absolute;
        top: 12px;
        right: 12px;
        background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
        color: #fff;
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 11px;
        font-weight: 600;
        box-shadow: 0 2px 8px rgba(251, 191, 36, 0.4);
        letter-spacing: 0.5px;
      }
    }

    .rank-list {
      display: flex;
      flex-direction: column;
      gap: 12px;

      .rank-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        border-radius: 10px;
        transition: all 0.2s ease;
        position: relative;
        background: #f9fafb;

        &:hover {
          background: #f3f4f6;
          transform: translateX(4px);
        }

        .rank-number {
          position: relative;
          width: 32px;
          height: 32px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 50%;
          font-weight: 700;
          font-size: 14px;
          flex-shrink: 0;

          .crown {
            position: absolute;
            top: -8px;
            right: -8px;
            font-size: 14px;
            animation: bounce 2s ease-in-out infinite;
          }
        }

        .rank-title {
          flex: 1;
          font-size: 13px;
          color: #374151;
          font-weight: 500;
          line-height: 1.4;
        }

        .rank-indicator {
          width: 4px;
          height: 24px;
          border-radius: 2px;
          flex-shrink: 0;
        }

        &.rank-first {
          background: linear-gradient(135deg, #fef3f2 0%, #fee2e2 100%);

          .rank-number {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: #fff;
            box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
          }

          .first-indicator {
            background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
          }
        }

        &.rank-second {
          background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);

          .rank-number {
            background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
            color: #fff;
            box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3);
          }

          .second-indicator {
            background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
          }
        }

        &.rank-third {
          background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);

          .rank-number {
            background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
            color: #fff;
            box-shadow: 0 2px 8px rgba(251, 191, 36, 0.3);
          }

          .third-indicator {
            background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
          }
        }
      }
    }
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

.loading {
  text-align: center;
  padding: 15px;
  font-size: 12px;
  color: #999;
}
</style>